import { Prop, SchemaFactory, Schema } from '@nestjs/mongoose';
import * as mongoose from 'mongoose';
import { Document, Types, ObjectId } from 'mongoose';
import { User } from './user.schema';

export type UserFocusDocument = UserFocus & Document;

/**
 * 用户关注（粉丝）表
 */
@Schema()
export class UserFocus {
    /**
     * 用户id
     */
    @Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User', index: true })
    user: User | ObjectId;
    /**
     * 被关注人id
     */
    @Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User', index: true })
    beFocusUser: User | ObjectId;

    /**
     * 创建时间
     */
    @Prop({
        default: Date.now,
    })
    createdAt: Date;
}

export const UserFocusSchema = SchemaFactory.createForClass(UserFocus);
UserFocusSchema.index({ user: 1, beFocusUser: 1 }, { unique: true });
